package top.hidoctor.auscultation.view;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import top.hidoctor.auscultation.R;

public class LabelView extends View {
    private Resources mResources;

    private int mTotalWidth, mTotalHeight;
    private Bitmap girlBitmap;
    private int girlBitWidth, girlBitHeight;
    private Rect girlSrcRect, girlDesRect;

    public LabelView(Context context) {
        super(context);
        mResources = getResources();
        initBitmap();
    }

    private void initBitmap() {
        //美女图片的宽和高
        girlBitmap = ((BitmapDrawable) mResources.getDrawable(R.mipmap.ww2)).getBitmap();
        girlBitWidth = girlBitmap.getWidth();
        girlBitHeight = girlBitmap.getHeight();


    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(girlBitmap, girlSrcRect, girlDesRect, null);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mTotalWidth = w;
        mTotalHeight = h;

        girlSrcRect = new Rect(0, 0, girlBitWidth, girlBitHeight);
        girlDesRect = new Rect(0, 0, girlBitWidth, girlBitHeight);

    }
}
